/**
 * Project Name:MVC
 * File Name:CheckLoginInterceptor.java
 * Package Name:cn.com.tupperware.interceptor
 * Date:Nov 4, 201611:03:00 AM
 * Copyright (c) 2016, chenzhou1025@126.com All Rights Reserved.
 *
*/

package cn.com.tupperware.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * ClassName:CheckLoginInterceptor <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: Nov 4, 2016 11:03:00 AM <br/>
 * 
 * @author upw023
 * @version
 * @since JDK 1.6
 * @see
 */
public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
	private static final Log LOGGER = LogFactory.getLog(CheckLoginInterceptor.class);

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("PreHandle");
		// intercept
		HttpSession session = request.getSession();
		if (session.getAttribute("currUser") == null) {
			LOGGER.info("require login but not login");
			response.sendRedirect("error.jsp");
			return false;
		} else {
			LOGGER.info(session.getAttribute("currUser") + "login");
			return true;
		}

	}
}
